package com.tencent.wxpay.demo.controller;

import com.tencent.wxpay.demo.service.CloseOrderService;
import com.tencent.wxpay.protocol.response.CloseOrderResData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 关闭订单服务控制层
 */
@Controller
@RequestMapping("closeOrder")
public class CloseOrderController {

    @Autowired
    private CloseOrderService closeOrderService;

    /**
     * 调用关闭订单接口
     * @param outTradeNo 订单号
     * @return
     */
    @RequestMapping("doCloseOrder")
    @ResponseBody
    public Map<String, Object> doUnifiedOrder(String outTradeNo) {
        Map<String,Object> map = new HashMap();
        if(StringUtils.isNotBlank(outTradeNo)) {
            CloseOrderResData closeOrderResData = closeOrderService.doCloseOrder(outTradeNo);
            if (null != closeOrderResData) {
                map.put("result",closeOrderResData);
                map.put("status", "success");
            } else {
                map.put("status","error");
                map.put("msg", "关闭订单失败，详细信息请查看服务端日志输出");
            }
        } else {
            map.put("status","error");
            map.put("msg", "关闭订单失败，订单号不能为空");
        }
        return map;
    }

}
